package com.sharein.auth.actions;

import java.io.IOException;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sharein.auth.business.UserManager;

public class Signin implements Action {

	@Override
	public boolean execute(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String shareinID = request.getParameter("shareinID");
		String persistent = request.getParameter("persistent");
		if(persistent != null) {
			Cookie cookieShareinID = new Cookie("shareinID", shareinID);
			cookieShareinID.setMaxAge(3600*24*30*12*3);
			response.addCookie(cookieShareinID);
		}
		else {
			HttpSession session = request.getSession();
			session.setAttribute("shareinID", shareinID);
		}
		UserManager.setUserSignedIn(shareinID, true);
		response.sendRedirect("home.html");
		return true;
	}

}
